#include "MainWindowShow.h"
#include "MenvWindowShow.h"

MainWindowShow::MainWindowShow(RtspDecodeThread& decThread,RunConfig& d_config,QWidget *parent,int width,int height)
    : QMainWindow(parent)
    , dec_thread(decThread)
    , ui_main(new Ui::MainWindow)
    , videoLabel(new QLabel(this))
    , sig(new SignalControl(d_config))//信号收发器
    , ss_signal(false) //默认为初始状态
{
    QFont ft;
    ft.setPointSize(14);

    ui_main->setupUi(this);

    // 设置QLabel的位置和大小
    videoLabel->setGeometry(0, 0, width, height); // 根据视频分辨率调整大小
    //设置按键字体和颜色
    ui_main->pushButton->setFont(ft);
    ui_main->pushButton_2->setFont(ft);
    QFont font( "Microsoft YaHei", 28, 75); 
    ui_main->run_show->setFont(font);
    ui_main->run_show->setStyleSheet("color: red;");

    //连接按键与槽,按键的响应
    connect(ui_main->pushButton,&QPushButton::clicked,this,&MainWindowShow::switch_rtsp_status_clicked);
    connect(ui_main->pushButton_2,&QPushButton::clicked,this,&MainWindowShow::poweroff_fun_clicked);

    //是否显示启停按键？
    if (d_config.getBool("Start-Stop_button_enable", true) == false)
    {
        /* 不显示 */
        ui_main->pushButton->hide();
    }
    
    
}
MainWindowShow::~MainWindowShow()
{
    delete ui_main;
    delete sig;
    delete videoLabel;
}
void MainWindowShow::updateFrame(const QImage &frame)
{
    // 在QLabel上显示新的视频帧
    videoLabel->setPixmap(QPixmap::fromImage(frame));
}
//启停按键
void MainWindowShow::switch_rtsp_status_clicked(){

    if (ss_signal == false)
    {
        /* 关闭，需要开启 */
        ui_main->pushButton->setText("停止");
        ss_signal=true;
        sig->Start_signal();
        std::cout << ">>> 测试开始~~~\r\n";
        ui_main->run_show->setText("运行中......");
    }else{
        /* 开启，需要关闭 */
        ui_main->pushButton->setText("开始");
        ss_signal=false;
        sig->Stop_signal();
        std::cout << ">>> 测试结束~~~\r\n";
        ui_main->run_show->setText(" ");
    }
    

}
//关机菜单显示
void MainWindowShow::poweroff_fun_clicked(){
    std::cout << ">>> 打开菜单页面\r\n";
    MenvWindowShow *aaa = new MenvWindowShow();
    aaa->show();//显示菜单
}
//警告弹窗处理
void MainWindowShow::handl_warnings(int a){
    QString message;
    // 根据参数a设置不同的警告信息
    switch (a) {
        case 1:
            message = "警告：无法查询到摄像头......";
            break;
        case 2:
            message = "警告：正在获取摄像头图像......请稍等......";
            break;
        default:
            message = "警告：未知错误。";
            break;
    }
    
    // 显示警告弹窗
    QMessageBox::warning(nullptr, "警告", message);

}


